package com.changil.nowonchangil.rest;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.changil.nowonchangil.controller.ServiceController;
import com.changil.nowonchangil.dto.History;
import com.changil.nowonchangil.dto.HistoryList;

@Path("/infos")
public class RestInfos {
	private ServiceController controller = new ServiceController();

	public void SetScoreService(ServiceController controller) {
		this.controller = controller;
	}

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("histories")
	public HistoryList getHistories(@QueryParam("fromId") int fromId,
			@QueryParam("count") int count,
			@QueryParam("isDownSide") boolean isDownSide) {
		HistoryList result = new HistoryList();
		ArrayList<History> list = null;
		list = controller.getHistories(fromId, count, isDownSide);
		result.size = list.size();
		result.list = list;
		return result;
	}

	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Path("histories")
	public String addHistory(@QueryParam("content") final String content) {
		String result = RestConstants.RESULT_SUCESS;
		controller.addHistory(content);
		return result;
	}

	@PUT
	@Produces(MediaType.APPLICATION_JSON)
	@Path("histories")
	public String modifyHistory(@QueryParam("id") final int id,
			@QueryParam("content") final String content) {
		String result = RestConstants.RESULT_SUCESS;
		controller.modifyHistory(id, content);
		result = RestConstants.RESULT_FAILED;
		return result;
	}

	@DELETE
	@Produces(MediaType.APPLICATION_JSON)
	@Path("histories")
	public String removeHistory(@QueryParam("id") final int id) {
		String result = RestConstants.RESULT_SUCESS;
		controller.removeHistory(id);
		return result;
	}
}
